<template>
  <div>
    <el-row :gutter="32">
      <el-col :span="12">
        <el-card>
          <el-form :model="formData">
            <el-row :gutter="32">
              <el-col :span="24">
                <el-form-item label="Token" label-position="top">
                  {{ formData.token }}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="32">
              <el-col :span="24">
                <el-form-item label="Webhook Token" label-position="top">
                  <el-input v-model="formData.webhookToken" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="32">
              <el-col :span="24">
                <el-form-item label="下单回调地址" label-position="top">
                  <el-input v-model="formData.orderCallbackUrl" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="32">
              <el-col :span="24">
                <el-form-item label="面单回调地址" label-position="top">
                  <el-input v-model="formData.labelCallbackUrl" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="32" type="flex" justify="center">
              <el-col :span="6">
                <el-button type="primary" @click="submit">保存</el-button>
              </el-col>
            </el-row>
          </el-form>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card header="可用渠道(如果无渠道,请联系客服添加渠道)">
          <el-table :data="table_body" border>
            <el-table-column prop="id" label="渠道代码" />
            <el-table-column prop="name" label="渠道名称" />
          </el-table>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import request from '@/utils/request'
import { copyProperty } from '@/utils/tools'
export default {
  data() {
    return {
      formData: {
        labelCallbackUrl: '',
        orderCallbackUrl: '',
        token: '',
        trackingCallbackUrl: '',
        webhookToken: ''
      },
      table_body: []
    }
  },
  created() {
    this.list()
  },
  methods: {
    list() {
      request({
        url: 'webhook/query',
        method: 'get'
      }).then(res => {
        if (res.success) {
          copyProperty(this.formData, res.data)
          this.table_body = res.data.channelOptions
        }
      })
    },
    submit() {
      request({
        url: 'webhook/add',
        method: 'post',
        data: this.formData
      }).then(res => {
        if (res.success) {
          this.$message.success(res.data)
        }
      })
    }
  }
}
</script>
<style>
    .demo-drawer-footer{
        width: 100%;
        position: absolute;
        bottom: 0;
        left: 0;
        border-top: 1px solid #e8e8e8;
        padding: 10px 16px;
        text-align: right;
        background: #fff;
    }

    .demo-upload-list{
        display: inline-block;
        width: 60px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0,0,0,.2);
        margin-right: 4px;
    }
</style>
